package layer
{
	import map.data.RadCell;
	
	import flash.geom.Point;
	
	import view.RadCellView;

	public class WalkCellLayer extends BaseLayer
	{
		private var _cells:Vector.<RadCellView>;
		public function WalkCellLayer()
		{
			super();
			_cells = new Vector.<RadCellView>();
			this.mouseEnabled = this.mouseChildren = false;
		}
		
		public function addCell(cell:RadCellView):void
		{
			for each(var c:RadCellView in _cells)
			{
				if(Point.distance(c.center,cell.center)<1)
				{
					return;
				}
			}
			_cells.push(cell);
			cell.mouseChildren = cell.mouseEnabled = false;
			cell.state = 1;
			addChild(cell);
		}
		
		override public function getData():*
		{
			var result:Vector.<RadCell> = new Vector.<RadCell>();
			for each(var cell:RadCellView in _cells)
			{
				result.push(cell.radCell);
			}
			return result;
		}
		
		public function removeCell(cell:RadCellView):void
		{
			var index:int = -1;
			for(var i:int =0;i<_cells.length;i++)
			{
				var c:RadCellView = _cells[i];
				if(Point.distance(c.center,cell.center)<1){
					index = i;
				}
			}
			if(index>-1)
			{
				cell = _cells[index];
				removeChild(cell);
				cell.state = 0;
				_cells.splice(index,1);
			}
		}
	}
}